package com.slwish.xty.adapter;


import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.slwish.xty.R;
import com.slwish.xty.entity.CreditTourismInfoModel;
import com.slwish.xty.entity.ServiceList;

import java.util.List;

/**
 * 模块说明：首页适配器
 *
 * @author 陈浩
 * @date 2017/11/28
 */
public class CreditTourismListAdapter extends BaseQuickAdapter<CreditTourismInfoModel, BaseViewHolder> {

    public CreditTourismListAdapter(@Nullable List<CreditTourismInfoModel> data) {
        super(R.layout.item_credit_tourism_list, data);
    }


    @Override
    protected void convert(BaseViewHolder helper, CreditTourismInfoModel item) {
        try {

//            int position = helper.getAdapterPosition();
            helper.setText(R.id.tv_num, item.getViewCount() + "").setText(R.id.tv_name, item.getScenicName())
                    .setText(R.id.tv_distance, item.getDistance() + "km")
                    .setText(R.id.tv_point, item.getPoint() + "分");
            helper.setGone(R.id.iv_is_sincerity, !item.getSincerityMerchant().equals("0"));
            List<ServiceList> serviceItem = item.getServiceItem();
            LinearLayout rl = helper.getView(R.id.ll_service_item);
            String imageUrl = item.getLogo().get(0);
            RequestOptions options = new RequestOptions();
            options.placeholder(R.mipmap.zhanweifu_home)
                    .error(R.mipmap.zhanweifu_home)
                    .skipMemoryCache(true);
            Glide.with(mContext).load(imageUrl).apply(options).into((ImageView) helper.getView(R.id.iv_head));
            rl.removeAllViews();
            for (ServiceList serviceItemBean : serviceItem) {
                String serviceName = serviceItemBean.getServiceName();
                View view = mLayoutInflater.inflate(R.layout.item_main_service_content, null);
                TextView tvItem = view.findViewById(R.id.tv_item);
                tvItem.setText(serviceName);
                rl.addView(view);
            }
        } catch (Exception e) {
        }
    }
}
